package com.xm_jd.controller.jiesuan;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.BalanceDao;
import com.xm_jd.model.entitys.Balance;
import com.xm_jd.model.entitys.tb_sh;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**�����ҳ��
 * Servlet implementation class BalanceServlet
 */
@WebServlet("/balancesel")
public class BalanceServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BalanceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				//�����ַ���
				request.setCharacterEncoding("utf-8");
				user aa=(user) request.getSession().getAttribute("users");
				//����
				//���Ҫ�������Ʒ����ѯ���ﳵ��Ҫ�������Ʒ��
				List<Balance> list = new BalanceDao().getBalance(aa.getUser_id());
				int jianshu=0;
				double zongj=0;
				for (Balance o : list) {
					jianshu+=o.getCar_gounum();
					zongj+=o.getCar_gounum()*o.getShoop_price().doubleValue();
					
				}
				request.getSession().setAttribute("jianshu", jianshu);
				request.getSession().setAttribute("zongj", zongj);
				
				//��ѯ��Ӧ�û����ջ���ַ���Ȳ�д��
				List<tb_sh> address = new BalanceDao().selectSh(aa.getUser_id());
				request.getSession().setAttribute("address", address);
				//�������ѯ����Ҫ�������Ʒ�б�����request������
				if(list.size()>0){
					request.getSession().setAttribute("buylist", list);
				}
				//ת��ҳ�浽jiesuan.jsp
				//request.getRequestDispatcher("jsps/JDjiesuan.jsp").forward(request, response);
				this.forward("JDjiesuan");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
